#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2024/12/30 19:18
# @Author : George


import asyncio
from threading import currentThread

"""
===========================python3.4 之后提供的用法====================
"""
# 这里经过装饰器装饰之后，普通函数就变为了协程函数，协程函数（）=>协程对象
@asyncio.coroutine
def f1():
    print("f1 开始执行", currentThread())
    yield from asyncio.sleep(2)  # yield from 后面添加的必须是生成器对象
    print("f1 结束执行", currentThread())

@asyncio.coroutine
def f2():
    print("f2 开始执行", currentThread())
    yield from asyncio.sleep(2)
    print("f2 结束执行", currentThread())


loop = asyncio.get_event_loop()  # 产生/获取 事件循环
loop.run_until_complete(asyncio.wait([f1(),f2()]))  # 这里面传递的就是协程对象
